package com.zhkj.txg.module.mine.vm


import android.app.Application
import android.util.Log
import androidx.lifecycle.MutableLiveData
import com.zhkj.lib.base.BaseViewModel
import com.zhkj.lib.http.HttpResponse
import com.zhkj.lib.http.ViewModelSubscribeListener
import com.zhkj.lib.utils.AccountManager
import com.zhkj.txg.module.mine.entity.DiamondResponse
import com.zhkj.txg.module.mine.entity.PayOrderResponse
import com.zhkj.txg.module.mine.entity.RefundListResponse
import com.zhkj.txg.module.mine.entity.SubmitOrderResponse
import com.zhkj.txg.module.mine.model.MineManager

class DiamondViewModel(application: Application) : BaseViewModel(application) {
    private val manager = MineManager()

    val diamondResponse = MutableLiveData<HttpResponse<DiamondResponse>>()
    val submitOrderResponse = MutableLiveData<HttpResponse<SubmitOrderResponse>>()
    val payOrderResponse = MutableLiveData<HttpResponse<PayOrderResponse>>()

    fun getUserCardList() {
        val listener = object : ViewModelSubscribeListener<DiamondResponse>(diamondResponse) {
            override fun onSuccess(resp: DiamondResponse) {
                super.onSuccess(resp)
            }
        }
        val refundList = manager.getUserCardList(listener)
        dispose.add(refundList)
    }

    fun sumbit(cardId: String, validDate: String, shopId: String) {
        val listener = object : ViewModelSubscribeListener<SubmitOrderResponse>(submitOrderResponse) {
            override fun onSuccess(resp: SubmitOrderResponse) {
                super.onSuccess(resp)
            }
        }
        val submitOrder = manager.getSubmitOrder(cardId, validDate, shopId, listener)
        dispose.add(submitOrder)
    }


    fun pay(orderSn: String, payType: String) {
        val listener = object : ViewModelSubscribeListener<PayOrderResponse>(payOrderResponse) {
            override fun onSuccess(resp: PayOrderResponse) {
                super.onSuccess(resp)
            }
        }
        val submitOrder = manager.getPayOrder(orderSn, payType, listener)
        dispose.add(submitOrder)
    }
}